<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>音乐列表</title>
</head>
<LINK media=screen href="bootstrap/css/bootstrap.css" type="text/css" rel="stylesheet">
<body>
<div class="container">
  <div class="hero-unit">
	<div id="content_list">
	  <p><a href="./">回到首页</a></p>
	  以下是本空间全部已上传音乐列表。本空间大小有限制（2G），在快满额的时候，系统将自动清除最旧的两首首音乐以释放本空间。
	    <?php 
			require("db.php");
			//计算共有几首音乐
		    $stor = new SaeStorage();
	        $domain = 'mp3';
	        $mp3_num=$stor->getFilesNum($domain);
			//计算已经占用了多少空间
	        $allsize=$stor->getDomainCapacity($domain);
	        $size_mb=number_format($allsize/(1024*1024),2);
			echo "本空间目前有".$mp3_num."首音乐，使用了".$size_mb."MB";
?>
		<!--  搜索框-->
		<form class="well form-search" action="">
		  <input type="text" class="input-medium search-query" name="key_word">
		  <button type="submit" class="btn">Search</button>
		</form>
<?php 
			//显示音乐列表.storage不支持文件名模糊搜索，所以列表还是从数据库读取。
			$page_size=10;//每页显示记录数
			$current_page=$_REQUEST['page']?$_REQUEST['page']:1;//第几页
			$from_record=($current_page-1)*$page_size;
			$key_word=$_REQUEST['key_word'];
		    if($key_word)
		    	{
		    		$sql="select * from mp3  where name like '%$key_word%' order by datetime desc limit $from_record,$page_size";
		    	}else{

		    		$sql="select * from mp3  order by datetime desc limit $from_record,$page_size";
		    	}
			$result=mysql_query($sql)OR die("<br>读取数据库错误！<br>");
			if($num=mysql_num_rows($result))
			{
			   echo "<div id='list'><table class='table'><tr>";
			   echo "<td>序号</td><td>操作</td><td>文件名</td><td>文件大小</td><td>&nbsp;上传日期&nbsp;上传时间&nbsp;&nbsp;</td></tr>";
			   while($row=mysql_fetch_array($result))
			   {
                             echo "<tr><td>".++$id."</td><td><a href=\"down.php?url=".$row['url']."\">下载</a>&nbsp;&nbsp;</td>";
				  echo "<td><a href=\"./?url=".$row['url']."\">".$row['name']."</a>&nbsp;&nbsp;</td>";
				  echo "<td>".number_format($row['size']/(1024*1024),2)."MB&nbsp;&nbsp;</td>";
				  echo "<td>".$row['datetime']."&nbsp;&nbsp;</td>";
				  echo "</tr>";
			  }
			  echo '<div>';
			 }
			mysql_close($conn);
		?>
	  </p>
	</div>
<p>
<div class="page" >
<?php 
echo '<a href="?page='.($current_page+1).'" ><strong >下一页</strong></a>';
if($current_page>=2)
{
  echo '<a href="?page='.($current_page-1).'"style="margin-left:40px;"><strong>上一页</strong></a>';
  echo '<a href="?page=1" style="margin-left:40px;"><strong>返回第一页</strong></a>';
}

?>
</p>
</div>
   </div>
</div>
</body>
</html>